package com.sdy.healthcode.biz.constants;

import lombok.Getter;
import lombok.Setter;

import java.awt.*;
import java.util.stream.Stream;

/**
 * 健康码类型
 * @author zhouziqiang 
 */
public enum HealthCodeType {
    /**
     * 绿码
     */
    GREEN("G", new Color(0x58b164), 0),
    /**
     * 黄码
     */
    YELLOW("Y", new Color(0xfdc12f), 10),
    /**
     * 红码
     */
    RED("R", new Color(0xfc0c1b), 100);

    @Getter
    @Setter
    private String code;

    @Getter
    @Setter
    private Color color;

    @Getter
    @Setter
    private Integer level;
    
    HealthCodeType(String code, Color color, Integer level) {
        this.code = code;
        this.color = color;
        this.level = level;
    }
    
    public static HealthCodeType from(String code) {
        return Stream.of(HealthCodeType.values()).filter(v -> v.code.equals(code)).findAny().orElse(null);
    }

    public static HealthCodeType fromLevel(Integer level) {
        return Stream.of(HealthCodeType.values()).filter(v -> v.level.equals(level)).findAny().orElse(null);
    }
}
